package jxta.chat;

import java.util.ArrayList;
import java.util.List;

import jxta.chat.entities.AbstractMessage;
import jxta.chat.entities.MessageFactory;
import jxta.chat.events.JxtaChatEvent;
import jxta.chat.events.JxtaChatListener;
import net.jxta.pipe.PipeMsgEvent;
import net.jxta.pipe.PipeMsgListener;

public class BidiPipeListener implements PipeMsgListener{

	List<JxtaChatListener> listeners = new ArrayList<JxtaChatListener>();
	
	public void addListener(JxtaChatListener listener){
		this.listeners.add(listener);
	}
	
	private void notifyListeners(JxtaChatEvent event){
		for (JxtaChatListener listener : listeners){
			listener.jxtaChatEvent(event);
		}
	}

	public void pipeMsgEvent(PipeMsgEvent event) {
		AbstractMessage am = MessageFactory.getInstance().getMessageClass(event.getMessage());
		JxtaChatEvent event2 = new JxtaChatEvent(am);
		notifyListeners(event2);
	}

}
